package com.li.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.li.util.PageUtils;
import com.li.util.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.li.pojo.Student;
import com.li.mapper.StudentMapper;
import com.li.service.StudentService;
import java.util.List;
import java.util.Map;

@Service
public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student> implements StudentService{

  /*  @Autowired
    DeptMapper deptMapper;
*/
    @Autowired
    StudentMapper studentMapper;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {


       /* String name = (String)params.get("name");
        Object currPage;
        currPage=params.get("currPage");
        params.put("page",currPage);
        params.put("limit","6");
        IPage<Student> page = this.page(
                new Query<Student>().getPage(params),
                new QueryWrapper<Student>().like(StringUtils.isNotBlank(name),"name", name));
*/
/*        List<Student> list=page.getRecords();
        for (Student student:list){
            Dept dept=deptMapper.selectById(student.getBid());
            student.setUsername(dept.getBname());
        }*/


            //方法二、通过sql语句实现
        String name = (String)params.get("name");
        params.put("limit","6" );
        IPage<Student> page1 =new Query<Student>().getPage(params);
        List<Student> list=this.baseMapper.qurey(page1,name);
        page1.setRecords(list);
        return new PageUtils(page1);


    }


/*


    //查询总条数
    @Override
    public int selectCount() {
        return studentMapper.selectCount();
    }



    //分页
    @Override
    public PageBean<Student> findByPage(int currentPage) {
        HashMap<String,Object> map = new HashMap<String,Object>();
        PageBean<Student> pageBean = new PageBean<Student>();

        //封装当前页数
        pageBean.setCurrPage(currentPage);

        //每页显示的数据
        int pageSize=8;
        pageBean.setPageSize(pageSize);

        //封装总记录数
        int totalCount = studentMapper.selectCount();
        pageBean.setTotalCount(totalCount);

        //封装总页数
        double tc = totalCount;
        Double num =Math.ceil(tc/pageSize);//向上取整
        pageBean.setTotalPage(num.intValue());

        map.put("start",(currentPage-1)*pageSize);
        map.put("size", pageBean.getPageSize());
        //封装每页显示的数据
        List<Student> lists = studentMapper.findByPage(map);
        pageBean.setLists(lists);

        return pageBean;

    }*/



}
